package ofxdownloader;

/**
 * Container class for bank account information retrieved from an OFX response
 * @author Alex Spurling / Chris Thornton
 *
 */
public class BankAccount extends Account {

	private String bankID;
	private String branchID;

	public BankAccount(String description, String bankID, String branchID, String accountID, String accountType) {
		this.description = description;
		this.bankID = bankID;
		this.branchID = branchID;
		this.accountID = accountID;
		this.accountType = accountType;
	}

	@Override
	public boolean equals(Object other) {
		if (other instanceof BankAccount) {
			BankAccount otherAcc = (BankAccount)other;
			return (description.equals(otherAcc.getDescription()) &&
					bankID.equals(otherAcc.getBankID()) &&
					branchID.equals(otherAcc.getBranchID()) &&
					accountID.equals(otherAcc.getAccountID()) &&
					accountType.equals(otherAcc.getAccountType()));
		}
		return false;
	}

	@Override
	public int hashCode() {
		return description.hashCode() + bankID.hashCode() + branchID.hashCode() + accountID.hashCode() + accountType.hashCode();
	}

	public String getBankID() {
		return bankID;
	}

	public String getBranchID() {
		return branchID;
	}

	public String getAccountOFXRequest(String ID, String fromDateTag, String toDateTag) {

		return
		"<BANKMSGSRQV1>\n" +
		"<STMTTRNRQ>\n" +
		"<TRNUID>" + ID + "\n" +
		"<STMTRQ>\n" +
		"<BANKACCTFROM>\n" +
		"<BANKID>" + bankID + "\n" +
		"<BRANCHID>" + branchID + "\n" +
		"<ACCTID>" + accountID + "\n" +
		"<ACCTTYPE>" + accountType + "\n" +
		"</BANKACCTFROM>\n" +
		"<INCTRAN>\n" +
		fromDateTag +
		toDateTag +
		"<INCLUDE>Y\n" +
		"</INCTRAN>\n" +
		"</STMTRQ>\n" +
		"</STMTTRNRQ>\n" +
		"</BANKMSGSRQV1>\n";

	}

}
